package top.milkbox.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import top.milkbox.info.R;
import top.milkbox.service.PostLikeService;

@RestController
@RequestMapping("/postLikes")
public class PostLikeController {

    @Autowired
    private PostLikeService postLikeService;

    @GetMapping("/likeOrCancel.login")
    public R likeOrCancel(@CookieValue("token") String token, Integer postId) {
        R r = new R();
        r.setFlag(true);
        int code = postLikeService.likeOrCancelLike(token, postId);
        if (code == 1) {
            r.setMessage("点赞成功");
        } else if (code == 2) {
            r.setMessage("取消点赞成功");
        } else {
            r.setFlag(false);
            r.setMessage("点赞或取消点赞异常");
        }

        return r;
    }

}
